﻿using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using Neptuno.Component;
using Neptuno.Model;
using System;

namespace Neptuno.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class PuertosService
    {
        PuertosComponent Component = new PuertosComponent();

        [WebInvoke(UriTemplate = "{id}", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool AgregarPuerto(string id, Puertos Puerto)
        {
            return Component.AgregarPuerto(Puerto);
        }

        [WebInvoke(UriTemplate = "{id}", Method = "DELETE", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool Borrar(string id)
        {
            return Component.Borrar(id);
        }

        [WebGet(UriTemplate = "Eliminados", ResponseFormat = WebMessageFormat.Json)]
        public List<Puertos> ListarEliminados()
        {
            List<Puertos> lista = Component.Listar(false);
            return lista;
        }

        [WebGet(UriTemplate = "", ResponseFormat = WebMessageFormat.Json)]
        public List<Puertos> Listar()
        {
            List<Puertos> lista = Component.Listar();
            return lista;
        }

        [WebGet(UriTemplate = "ByPais/{idPais}/{skip}/{range}", ResponseFormat = WebMessageFormat.Json)]
        public List<Puertos> ListarByPais(string idPais, string skip, string range)
        {
            int IdPais = int.Parse(idPais);
            int? Skip = !string.IsNullOrWhiteSpace(skip) ? new int?(int.Parse(skip)) : null;
            int? Range = !string.IsNullOrWhiteSpace(range) ? new int?(int.Parse(range)) : null;

            List<Puertos> lista = Component.ListarByPais(IdPais, Skip, Range);
            return lista;
        }

        [WebGet(UriTemplate = "{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public Puertos GetById(string id)
        {
            return Component.GetById(id);
        }

        [WebInvoke(UriTemplate = "{id}", Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool Actualizar(string id, Puertos Puerto)
        {
            Puerto.idPuerto = id;
            return Component.Actualizar(Puerto);
        }

        [WebGet(UriTemplate = "Restaurar/{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool Restaurar(string id)
        {
            return Component.Habilitar(id);
        }
    }
}